package per.ethan.javase.java8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * @author Ethan
 * @date 2020/05/06 10:59
 */
public class Demo2 {

    public static void main(String[] args) {
        Demo2.testConsumer(400d, money -> System.out.println("消费金额：" + money));

        List<Integer> list = Arrays.asList(50, 100, 60, 35, 25);
        List<Integer> result = Demo2.testPredicate(list, (num) -> num > 50);
        result.forEach(System.out::println);
    }

    private static void testConsumer(Double money, Consumer<Double> consumer) {
        consumer.accept(money);
    }

    private static List<Integer> testPredicate(List<Integer> list, Predicate<Integer> predicate) {
        List<Integer> result = new ArrayList<>();

        list.forEach(item -> {
            if (predicate.test(item)) {
                result.add(item);
            }
        });

        return result;
    }

}
